package duxiaomang;

import java.util.Scanner;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-9-5下午 03:48
 */
public class Test2 {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int n = sc.nextInt();
        sc.nextLine();
        while (n-- > 0) {
            String temp = sc.nextLine();
            Boolean flag = true;
            for (int i = 0; i < temp.length(); i++) {
                char a = str.charAt(i); //字母
                char b = temp.charAt(i); // 数字
                if (a == 'X') {
                    if (b == '1') {
                        flag = false;
                        break;
                    }
                } else {
                }
            }
            if (flag) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}
